#include <algorithm>
#include <vector>
#include <iostream>
#include <functional>
#include <iterator>

using namespace std;

void show(int x){
	cout<<x<<" ";
}

void print_module_2(int x){
	if(x%2==0){
		cout<<x<<" ";
	}
}

class Add{
public:
	Add(int i=2):howmuch(i){}
	
	void operator()(int& i){
		i+=howmuch;
	}
private:
	int howmuch;
};

bool odd(int x){
	return x%5==0;
}

class Myrand{
public:
	Myrand(int r):range(r){}
	int operator()(){
		return rand()%range;
	}
private:
	int range;	
};

int main(){
	vector<int> v;
	for(size_t i=0;i<10;i++){
		v.push_back(i);
	}
	
	for_each(v.begin(),v.end(),show);
	cout<<"\n";
	
	for_each(v.begin(),v.end(),Add());
	
	for_each(v.begin(),v.end(),show);
	cout<<"\n";
	for_each(v.begin(),v.end(),print_module_2);
	cout<<"\n";
	
	vector<int>::iterator it=find_if(v.begin(),v.end(),odd);
	if(it!=v.end()){
		cout<<"found "<<*it<<"\n";
	}
	vector<int>::const_iterator cit=find_if(v.begin(),v.end(),bind2nd(modulus<int>(),5));
	if(cit!=v.end()){
		cout<<"found "<<*cit<<"\n";
	}
	for_each(v.begin(),v.end(),show);
	cout<<"\n";

	//generate_n(v.begin(),10,Myrand(100));
	for_each(v.begin(),v.end(),show);
	cout<<"\n";
	
	ostream_iterator<int> oit(cout," ");
	copy(v.begin(),v.end(),oit);
	cout<<"\n";
	rotate(v.begin(),v.begin()+1,v.end());
	copy(v.begin(),v.end(),oit);
	cout<<"\n";
	
	random_shuffle(v.begin(),v.end());
	copy(v.begin(),v.end(),oit);
	cout<<"\n";
}

